project(xrootd-dm)
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)

set(CMAKE_CXX_FLAGS "-g -Wall -Wextra")

set (XRDDMSYS_FOUND XRDDMSYS_FOUND-NOTFOUND)
set(XRDDMSYS $ENV{XRDDMSYS})
if(NOT XRDDMSYS)
  set(XRDDMSYS ${CMAKE_CURRENT_SOURCE_DIR})
endif(NOT XRDDMSYS)

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
set(CMAKE_INSTALL_PREFIX ${XRDDMSYS})

set(XRDDM_VERSION_MAJOR 0)
set(XRDDM_VERSION_MINOR 1)

find_package(Threads REQUIRED)

find_package(XROOTD REQUIRED)
find_package(ALIEN REQUIRED)
find_package(ROOT)
find_package(APPMON)

MESSAGE(STATUS "Checking root.exe ...")
FIND_PROGRAM(ROOT_EXE NAME root.exe PATHS $ENV{ROOTSYS}/bin /usr/local/bin /usr/bin /bin NO_DEFAULT_PATH )
if (ROOT_EXE)
	MESSAGE(STATUS "Found root.exe in ${ROOT_EXE}")
endif (ROOT_EXE)

MESSAGE(STATUS "Checking zip ...")
FIND_PROGRAM(XRDDM_ZIP NAME zip PATHS /usr/local/bin /usr/bin /bin NO_DEFAULT_PATH )
if (XRDDM_ZIP)
    MESSAGE(STATUS "Found zip in ${XRDDM_ZIP}")
endif (XRDDM_ZIP)


if(APPMON_FOUND)
  option(HAS_APPMON "Using AppMon" ON)
endif(APPMON_FOUND)

configure_file(
  "${PROJECT_SOURCE_DIR}/src/XrddmConfig.h.in"
  "${PROJECT_BINARY_DIR}/src/XrddmConfig.h"
)

include_directories("${PROJECT_BINARY_DIR}/src/")

add_subdirectory(src)

# try_compile(HAS_APPMON
#   ${CMAKE_BINARY_DIR}
#   ${PROJECT_SOURCE_DIR}/src/testHasAppMon.cpp
# )

# try_run(RUN_HAS_APPMON
#   COMPILE_HAS_APPMON
#   ${CMAKE_BINARY_DIR}
#   "${PROJECT_SOURCE_DIR}/src/testHasAppMon.cpp"
#   OUTPUT_HAS_APPMON OUTPUT
# )

# include_direco

include(CPack)

#include(CTest)

add_test(xrd-dmRuns ${XRDDMSYS}/bin/xrd-dm)
add_test(xrd-dm-simRuns ${XRDDMSYS}/bin/xrd-dm-sim)


# uninstall
CONFIGURE_FILE(
  "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
  "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  IMMEDIATE @ONLY)

ADD_CUSTOM_TARGET(uninstall
  "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
